// test-model.js
const db = require('./models')
console.log('db对象:', Object.keys(db))

const { sequelize, bank_transaction, sales_order, customer } = db
console.log('bank_transaction:', bank_transaction)
console.log('sales_order:', sales_order)
console.log('customer:', customer)

async function testModels() {
  try {
    console.log('测试数据库连接...')
    await sequelize.authenticate()
    console.log('数据库连接成功')
    
    if (bank_transaction) {
      console.log('测试bank_transaction模型...')
      const transactions = await bank_transaction.findAll({
        limit: 5
      })
      console.log(`找到 ${transactions.length} 条银行流水`)
    } else {
      console.log('bank_transaction模型未定义')
    }
    
    if (sales_order) {
      console.log('测试sales_order模型...')
      const orders = await sales_order.findAll({
        limit: 5
      })
      console.log(`找到 ${orders.length} 条销售订单`)
    } else {
      console.log('sales_order模型未定义')
    }
    
    if (customer) {
      console.log('测试customer模型...')
      const customers = await customer.findAll({
        limit: 5
      })
      console.log(`找到 ${customers.length} 个客户`)
    } else {
      console.log('customer模型未定义')
    }
    
    console.log('模型测试完成!')
    process.exit(0)
  } catch (error) {
    console.error('模型测试失败:', error)
    process.exit(1)
  }
}

testModels()